<?php
$deId = $_GET['pid'] > 0 ? $_GET['pid'] : $_POST['deId'];

if ($deId < 1 || $deId == '') {

    header('Location: aktie_list.php');
    exit;
}
error_reporting(E_ALL);

include_once('controller/includes/constants.php');
include_once('controller/includes/db_access.php');

if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {


    $naam = stripslashes($_POST['naam']);
    $code = stripslashes($_POST['code']);
    $waarde = stripslashes($_POST['waarde']);
    $aktief = $_POST['aktief'];
    $pro_id = $_POST['deId'];

// Insert a new user into the `user` table  
    $q = new Query;
    $q
            ->update('`aktie`')
            ->set(
                    array(
                        '`naam`' => $naam,
                        '`waarde`' => $waarde,
                        '`code`' => $code,
                        '`aktief`' => $aktief
                    )
            )
            ->from('`aktie`')
            ->where_equal_to(
                    array(
                        '`aktie`.`aktie_id`' => $pro_id
                    )
            )
            ->limit(1);

    $result = $q->run();

    if (($result && $q->get_affected() > 0)) {

        header('Location: aktie_list.php');
    }
}

if (isset($_GET['pid'])) {

    $id = $_GET['pid'];
    $q = new Query;
    $q
            ->select('*'
            )
            ->from('`aktie`')
            ->where_equal_to(
                    array(
                        '`aktie`.`aktie_id`' => $id,
                    )
    );

    $result = $q->run();

    if (!($result > 0)) {
        $Error = 'No category found.' . "\n";
    } else {
        $rows = mysql_fetch_object($result);
    }
}
?>
<link rel="stylesheet" href="styles/screen.css" type="text/css" charset="utf-8" media="screen" />
<table border="0" cellspacing="5" cellpadding="5">
    <thead>
        <tr>
            <th colspan="2"><h1><?php include_once('controller/includes/header.php'); ?></th>
        </tr>
        </thead>
        <tbody>
        <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
            <input type="hidden" name="action" value="multiple" />
            <input type="hidden" name="deId" value="<?php echo $deId; ?>" /> 
            <tr>
                <td colspan="2"><h1>categorie add</h1><br/><br/>
<?php
if (isset($Error)) {
    echo $Error;
}
?></td>
            </tr>

            <tr>
                <td valign="top">naam:
                </td>
                <td valign="top">
                    <input type="text" name="naam" value="<?php echo $rows->naam; ?>" size="20" />

                </td>
            </tr>
            <tr>
                <td valign="top">Code:
                </td>
                <td valign="top">
                    <input type="text" name="code" value="<?php echo $rows->code; ?>" size="10" />

                </td>
            </tr>
            <tr>
                <td valign="top">waarde:
                </td>
                <td valign="top">
                    <input type="number" min="1" name="waarde"  max ="100" value="<?php echo $rows->waarde; ?>" required = "required" />%

                </td>
            </tr>
            <tr>
                <td valign="top">aktief:
                </td>
                <td>
                    <input name="aktief" type="radio"  id="aktief" value="Y" <?php if ($rows->aktief == 'Y')
    echo ' checked';
?> /> Ja 
                    <input name="aktief" type="radio"  id="aktief" value="N" <?php if ($rows->aktief != 'Y')
    echo ' checked';
?> /> Nee</td>
            </tr>
            <tr>
                <td valign="top">aktief:
                </td>
                <td>
                    <input type = "submit" name="save" value="save" size="10" />
                </td>
            </tr>